﻿using System;
using Dsl.Ped.Common.Exceptions;
using Dsl.Ped.Common.Helpers;
using NUnit.Framework;

namespace DSLPedCommonTest.Helpers
{
    [TestFixture]
    public class XamlHelperTest
    {
        [Test]
        public void CheckValidXamlNameTest1()
        {
            try
            {
                XamlHelper.CheckValidXamlName(null);
            }
            catch (InvalidStringException exc)
            {
                if (!exc.Message.Contains("Must not be null"))
                {
                    throw new Exception("unexpected exception: " + exc);
                }
            }
        }

        [Test]
        public void CheckValidXamlNameTest2()
        {
            try
            {
                XamlHelper.CheckValidXamlName("");
            }
            catch (InvalidStringException exc)
            {
                if (!exc.Message.Contains("Must not be null"))
                {
                    throw new Exception("unexpected exception: " + exc);
                }
            }
        }

        [Test]
        public void CheckValidXamlNameTest3()
        {
            try
            {
                XamlHelper.CheckValidXamlName(".aa");
            }
            catch (InvalidStringException exc)
            {
                if (!exc.Message.Contains("Must start with a letter or underscore"))
                {
                    throw new Exception("unexpected exception: " + exc);
                }
            }
        }

        [Test]
        public void CheckValidXamlNameTest4()
        {
            var result = XamlHelper.CheckValidXamlName("aa");
            Assert.AreEqual("aa", result);
        }


        [Test]
        public void CheckValidXamlNameTest5()
        {
            var result = XamlHelper.CheckValidXamlName("_a");
            Assert.AreEqual("_a", result);
        }


        [Test]
        public void CheckValidXamlNameTest6()
        {
            try
            {
                XamlHelper.CheckValidXamlName("1aa");
            }
            catch (InvalidStringException exc)
            {
                if (!exc.Message.Contains("Must start with a letter or underscore"))
                {
                    throw new Exception("unexpected exception: " + exc);
                }
            }
        }

        [Test]
        public void CheckValidXamlNameTest7()
        {
            XamlHelper.CheckValidXamlName("a1a");
            XamlHelper.CheckValidXamlName("ac1");
            XamlHelper.CheckValidXamlName("a_");
            XamlHelper.CheckValidXamlName("___");
        }

        [Test]
        public void CheckValidXamlNameTest8()
        {
            try
            {
                XamlHelper.CheckValidXamlName("a.a");
            }
            catch (InvalidStringException exc)
            {
                if (!exc.Message.Contains("Forbidden character '.' on a position 1. Use letter, digit or underscore instead"))
                {
                    throw new Exception("unexpected exception: " + exc);
                }
            }
        }

        [Test]
        public void CheckValidXamlNameTest9()
        {
            try
            {
                XamlHelper.CheckValidXamlName("a a");
            }
            catch (InvalidStringException exc)
            {
                if (!exc.Message.Contains("Forbidden character ' ' on a position 1. Use letter, digit or underscore instead"))
                {
                    throw new Exception("unexpected exception: " + exc);
                }
            }
        }

        [Test]
        public void CheckValidXamlNameTest10()
        {
            XamlHelper.CheckValidXamlName("");
        }
    }
}
